$(function () {
  $("#post-message-dialog").dialog({
    autoOpen: false,
    bgiframe: true,   
    modal: true,
    width: 630, 
    open: function () {
    },
    close: function () {
      $(this).find("textarea").val("");
    },
    buttons: {
      'submit': function () {
        try {
          var msg = post_message($("#post-message-dialog .username").text(), $(this).children('textarea').val())
          $("#post-message-dialog #hint").text(gettext("your message sent ok!")).show("");
          $('#post-message-dialog textarea').val("");
          $('#post-message-dialog').dialog("close");
          // add to message list 
        } catch (e) {
          $("#post-message-dialog #hint").text(e.message).show();
        }
      }
    }
  });
  $("#post-message-dialog").max_length({max_length: 200});
  $("#post-message-dialog textarea").keypress(function () {
      $("#post-message-dialog #hint").hide();
  });
  $(".message a:last-child").click(function () {
      open_post_message_dialog($(this).children("#username").text());
  });
})
